/**
 * User: Allen
 * Date: 12-4-27
 */
window.onload=function(){
    new ToTop($('toTop'),765);
    new ReplyIt(getByClass('text'),50,50,'向老师提问');
    new ReplyIt(getByClass('replyMes'),24,50,'回复给老师');
    var model=$('model');
    var msgContent=$('content');
    var fm=$('submit1');
    model.style.display='none';
    fm.onsubmit = function(evt){
        if (evt) {
            evt.preventDefault();
        }
        else {
            window.event.returnValue = false;
        };
        var content=msgContent.value;
        if (content) {
            var newSection =model.cloneNode(true),
                msgDateSpan = getByClass('timeSpan', newSection)[0],
                msgContentDiv = getByClass('contentSpan', newSection)[0];
            newSection.style.display='block';
            msgDateSpan.innerHTML ='时间：'+ date('Y-m-d H:i:s');
            msgContentDiv.innerHTML = htmlEncode(content);
            var div=document.createElement('div');
            div.appendChild(newSection);
            model.parentNode.appendChild(div);

        }
    };
}
function ReplyIt(replyText,rHeight,height,txt){
    this.replyText=replyText;
    this.rHeight=rHeight;
    this.height=height || 50;
    this.txt= txt || '回复给老师';
    var _this=this;
    for(var i=0;i<this.replyText.length;i++){
        this.replyText[i].value=this.txt;
        this.replyText[i].onfocus=function(){
            if(this.value==_this.txt){
                this.value='';
            }
           this.style.height=_this.height+'px';
          nextNode(this).style.display='block';
           nextNode(this).onmouseover=function(){
                this.style.color='#F9931C';
            }
            nextNode(this).onmouseout=function(){
                this.style.color='#C7C7C7';
            }
        }
        this.replyText[i].onblur=function(){
            if(!this.value){
                this.value=_this.txt;
                this.style.height=_this.rHeight+'px';
                nextNode(this).style.display='none';
            }
        }
    }
}
function ToTop(btn,constant,topSpace){
    this.btn=btn;
    this.topSpace=topSpace || 0;
    this.constant=constant;
    this.btn.onclick=function(){
        window.scrollTo(0,0);
    }
    var _this=this;
    window.onresize=function(){
        _this.getWinSize();
    }
    window.onscroll=function(){
        _this.scroll();
    }
    this.getWinSize();
    this.scroll();
}
ToTop.prototype={
    getWinSize:function(){
        var width=window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
        this.btn.style.right=(width-this.constant)/2 + "px";
    },
    scroll:function(){
        if(document.documentElement.scrollTop>this.topSpace){
            this.btn.style.display='block';
        } else
        if(document.body.scrollTop>this.topSpace){
            this.btn.style.display='block';
        } else{
            this.btn.style.display='none';
        }
    }
}